package com.youyi.dutyChain;

/**
 * @author youyi.time
 * @date 2024/11/22 23:23
 */
public abstract class IHandler<T,R> {

    private IHandler<T,R> nextHandler; //下一个处理节点

    public IHandler getNextHandler() {
        return nextHandler;
    }

    public void setNextHandler(IHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public boolean hasNext() {
        return getNextHandler() != null;
    }

    /**
     * 责任链处理逻辑，
     * @return
     */
    public R handle(T t){
        if(hasNext()) return nextHandler.handle(t);
        return  null;
    }
}
